package com.steve.xfood.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author steve
 * @date 2020/5/13 6:18 上午
 */
@RestController
@RequestMapping("/weixin")
@Slf4j
public class WeiXinAuthTestController {

    @GetMapping("/auth")
    public void auth(@RequestParam("code") String code) {
        log.info("进入到auth方法中......");
        log.info("code={}", code);
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx836de3f27beea7b6&secret=d786a89324d42ad96204c02cb4b528b4&code="+ code +"&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        //响应结果
        String response = restTemplate.getForObject(url, String.class);
        log.info("response={}", JSON.parse(response));
    }
}
